package com.bootdo.backlist.service.impl;

import com.bootdo.backlist.converter.ConvertDomainUtils;
import com.bootdo.common.utils.KeyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.bootdo.backlist.dao.AppuserDao;
import com.bootdo.backlist.domain.AppuserDO;
import com.bootdo.backlist.dto.AppuserDTO;
import com.bootdo.backlist.service.AppuserService;
import com.bootdo.backlist.converter.ConvertDomainUtils;
import com.bootdo.common.utils.R;



@Service
public class AppuserServiceImpl implements AppuserService {
	@Autowired
	private AppuserDao appuserDao;
	
	@Override
	public AppuserDTO get(Long userId){
			AppuserDO appuserDO = appuserDao.get(userId);
			if (appuserDO != null){
                return ConvertDomainUtils.convertObject(appuserDO,AppuserDTO.class);

            }
			return null;
	}
	
	@Override
	public List<AppuserDTO> list(Map<String, Object> map){
		return ConvertDomainUtils.convertList(appuserDao.list(map),AppuserDTO.class);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return appuserDao.count(map);
	}
	
	@Override
	public R save(AppuserDTO appuser){
		appuser.setUserId(Long.valueOf(KeyUtil.getInstance().genUniqueKey64()));
		appuser.setIntegral(BigDecimal.ZERO);
	    int i = appuserDao.save(ConvertDomainUtils.convertObject(appuser,AppuserDO.class));
        return R.result(i);
	}
	
	@Override
	public R update(AppuserDTO appuser){
	    int i = appuserDao.update(ConvertDomainUtils.convertObject(appuser,AppuserDO.class));
		return R.result(i);
	}
	
	@Override
	public R remove(Long userId){
	    int i = appuserDao.remove(userId);
		return R.result(i);
	}
	
	@Override
	public R batchRemove(Long[] userIds){
	    int i = appuserDao.batchRemove(userIds);
		return R.result(i);
	}

	@Override
	public AppuserDTO login(AppuserDTO appuser) {
		AppuserDO login = appuserDao.login(ConvertDomainUtils.convertObject(appuser, AppuserDO.class));
		if (login != null) {
			return ConvertDomainUtils.convertObject(login,AppuserDTO.class);
		}
		return null;
	}

}
